package com.example.reflect.demo07.annotation;

import com.sun.istack.internal.NotNull;

import java.lang.reflect.Method;
import java.lang.annotation.Annotation;

public class Test {
    public static void main(String[] args) throws NoSuchMethodException {
        Class<Person> personClass = Person.class;

        Method hello = null;
        try {

            hello = personClass.getMethod("hello", String.class, String.class);
        }
        catch (NoSuchMethodException noSuchMethodException) {
            System.out.println("没找方法");
        }


        // 获取所有参数的Annotation:
        Annotation[][] annotations = hello.getParameterAnnotations();

        // 第一个参数（索引为0）的所有Annotation:
        Annotation[] annosOfName = annotations[0];

        for (Annotation anno : annosOfName) {
            // @Range注解
            if (anno instanceof Range) {
                Range range=(Range)anno;
                int max = range.max();
                System.out.println("读取到name的Range的最大值"+max);
            }
            // @NotNull注解
            if (anno instanceof NotNull) {
                NotNull notNull=(NotNull)anno;
                System.out.println("读取到name的NotNull");
            }
        }




    }


}
